<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix='sec'
	uri='http://www.springframework.org/security/tags'%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<script type="text/javascript" src="scripts/boot.js"></script>
</head>
<body style="border: 0px; margin: 0px; padding: 0px;width: 100%;height: 100%">
	<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
	    <table style="width:100%;">
	        <tr>
	            <td style="width:100%;"></td>
	            <td style="white-space:nowrap;">
	            	<span>编号：</span>
	                <input id="serialNum" class="mini-textbox" emptyText="请输入编号" style="width:120px;"/>
	            	<span>调出仓库：</span>
	                <input id="recallWhName" class="mini-textbox" emptyText="请输入调出仓库名称" style="width:120px;"/>
	                <span>调入仓库：</span>
	                <input id="callWhName" class="mini-textbox" emptyText="请输入调入仓库名称" style="width:120px;"/>
	            </td>
	            <td style="white-space:nowrap;">
                	<a class="mini-button" iconCls="icon-search" onclick="search()">查询</a>
                </td>
	        </tr>
	    </table>
	</div>
	<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
		<table style="width:100%;">
	      	 <tr>
	            <td style="width:100%;">
	            	<sec:authorize url='/allocation_add.do'>
	                <a class="mini-button" iconCls="icon-add" onclick="add()">增加</a>
	                </sec:authorize>
	                <sec:authorize url='/allocation_edit.do'>
	                <a class="mini-button" iconCls="icon-edit" onclick="edit()">修改</a>
	                </sec:authorize>
	                <sec:authorize url='/allocation_del.do'>
	                <a class="mini-button" iconCls="icon-remove" onclick="remove()">删除</a>
	                </sec:authorize>
	            </td>
	        </tr>
	    </table>
	</div>
	<div class="mini-fit" >
	<div id="datagrid1" class="mini-datagrid" idField="id" pageSize="20" url="allocation_view.do" style="width:100%;height:100%;" multiSelect="true">
		<div property="columns">
			<div type="indexcolumn"></div>
			<div type="checkcolumn"></div>
			<div name="action" width="60" headerAlign="center" align="center" renderer="onActionRenderer">相关操作</div>
			<div field="serialNum" width="100" headerAlign="center" align="center">编号</div>
			<div field="title" width="150" headerAlign="center" align="center">标题</div>
			<div field="recallWhName" width="100" headerAlign="center" align="center">调出仓库</div>
			<div field="callinWhName" width="100" headerAlign="center" align="center">调入仓库</div>
			<div field="status" width="70" headerAlign="center" align="center">状态</div>
			<div field="writeUserName" width="50" headerAlign="center" align="center">填单人</div>
			<div field="auditUserName" width="50" headerAlign="center" align="center">审核人</div>
		</div>
	</div>
	</div>

<script type="text/javascript">
	mini.parse();
	
	var grid = mini.get("datagrid1");
	grid.load();

	function search(){
	     var serialNum = mini.get("serialNum").getValue();
	     var recallWhName = mini.get("recallWhName").getValue();
	     var callWhName = mini.get("callWhName").getValue();
	     grid.load({ 
        	serialNum: serialNum,
        	recallWarehouseName: recallWhName,
        	callinWarehouseName: callWhName
	     });
	}
	//相关操作
 	function onActionRenderer(e) {
	    var s = '';
		if('3' == e.row.statusVal){
			s = '<sec:authorize url="/allocation_detail_init.do"><a href="javascript:editDetail()">编辑明细</a></sec:authorize>';
		}else{
			s = '<sec:authorize url="/allocation_data_view.do"><a href="javascript:viewDetail()">查看详细</a></sec:authorize>';
		}
	    return s;
    }
	
	function add() {
	    mini.open({
	        url: "allocation_add.do",
	        allowResize:false,
	        title: "新增仓库调拨单", width: 500, height: 360,
	        onload: function () {
	        },
	        ondestroy: function (action) {
	        	if(action == 'succ'){
	        		mini.showMessageBox({
	                    title: "提示",
	                    showModal:false,
	                    iconCls: "mini-messagebox-info",
	                    message: "保存成功！",
	                    timeout: 3000,
	                    x: 'right',
	                    y: 'bottom'
	                });
		            grid.reload();
	        	}
	        }
	    });
	}
	
	function edit() {
        var row = grid.getSelecteds();
        if (row.length == 1) {
        	if(row[0].statusVal == '3'){
        		mini.open({
                    url: "allocation_edit.do",
                    allowResize:false,
                    title: "修改仓库调拨单", width: 500, height: 360,
                    onload: function () {
                        var iframe = this.getIFrameEl();
                        var data = { action: "edit", row: row[0] };
                        iframe.contentWindow.SetData(data);
                    },
                    ondestroy: function (action) {
                    	if(action == 'succ'){
        	        		mini.showMessageBox({
        	                    title: "提示",
        	                    showModal:false,
        	                    iconCls: "mini-messagebox-info",
        	                    message: "修改成功！",
        	                    timeout: 3000,
        	                    x: 'right',
        	                    y: 'bottom'
        	                });
        		            grid.reload();
        	        	}
                    }
                });
        	}else{
        		mini.alert("已完成调拨，无法修改！");
        	};
        } else {
        	mini.alert("请选中一条记录");
        }
    }
	
    function remove() {
    	var rows = grid.getSelecteds();
    	var flag = true;
    	for(var i = 0;i<rows.length;i++){
    		if(rows[i].statusVal != '3') {
    			flag = false;
    		}
    	}
		if (rows.length > 0) {
	      	if(flag) {
	      		mini.confirm("确定删除选中记录？", "删除",function (action) {
	      			if (action == "ok") {
	                	   var arr = new Array();
		               		$.each(rows,function(i,v){
		               			arr.push(v.id);
		               		});
		               		var rids = arr.join("-");
		                   $.post("allocation_del.do",{id:rids},function(data){
		                		mini.showMessageBox({
		                            title: "提示",
		                            showModal:false,
		                            iconCls: "mini-messagebox-info",
		                            message: "已删除！",
		                            timeout: 3000,
		                            x: 'right',
		                            y: 'bottom'
		                        });
		                   		grid.reload();
		                   	},"json");
	                   }
	           	});	
	       	}else {
	       		mini.alert("已调拨完成，无法删除！");
	       	};
        } else {
            mini.alert("请选中一条记录");
        }
    }
    
    function editDetail() {
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "allocation_detail_init.do",
                allowResize:false,
                title: "编辑调拨明细", width: 900, height: 600,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { action: "editDetail", row: row };
                    iframe.contentWindow.SetData(data);
                },
                ondestroy: function (action) {
                	if(action == 'succ'){
    	        		mini.showMessageBox({
    	                    title: "提示",
    	                    showModal:false,
    	                    iconCls: "mini-messagebox-info",
    	                    message: "提交审核成功！",
    	                    timeout: 3000,
    	                    x: 'right',
    	                    y: 'bottom'
    	                });
    		            grid.reload();
    	        	}
                }
            });
        } else {
            alert("请选中一条记录");
        }
    }
    
    function viewDetail() {
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "allocation_data_view.do",
                allowResize:false,
                title: "调拨详细数据", width: 900, height: 600,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { action: "viewDetail", row: row };
                    iframe.contentWindow.SetData(data);
                }
            });
        } else {
            alert("请选中一条记录");
        }
    }
    
</script>
</body>
</html>